import Vue from 'vue'
import Router from 'vue-router'
import Meta from 'vue-meta'

import DefaultRoute from './defaultRoute'
import OriginRoute from './origin'
import TestRoute from './test'
import SysManageRoute from './sysManage'
import FinalResultRoute from './finalResult'
import RiskToolRoute from './riskTool'
import ThirdReportRoute from './thirdReport'
import InterfaceRoute from './interface'
import ChartsRoute from './charts'

// Layouts
import Layout1 from '@/layout/Layout1'
import Layout2 from '@/layout/Layout2'

Vue.use(Router)
Vue.use(Meta)

// 最终的路由列表
const ROUTERS = [
  // Default route
  {
    path: '',
    redirect: '/dashboards/home'
  }
].concat(DefaultRoute)
  .concat(OriginRoute)
  .concat(TestRoute)
  .concat(SysManageRoute)
  .concat(FinalResultRoute)
  .concat(RiskToolRoute)
  .concat(ThirdReportRoute)
  .concat(InterfaceRoute)
  .concat(ChartsRoute)

// console.log(ROUTERS)

// 路由管理器
const router = new Router({
  base: '/admin-web/',
  mode: 'history',
  routes: [{
    path: '/',
    component: Layout2,
    children: ROUTERS
  },{
    component: () => import('@/components/authentication/LoginV3'),
    path: '/authentication/login'
  }]
})

router.afterEach(() => {
  // On small screens collapse sidenav
  if (window.layoutHelpers && window.layoutHelpers.isSmallScreen() && !window.layoutHelpers.isCollapsed()) {
    setTimeout(() => window.layoutHelpers.setCollapsed(true, true), 10)
  }
})

router.beforeEach((to, from, next) => {
  // Set loading state
  document.body.classList.add('app-loading')

  // Add tiny timeout to finish page transition
  setTimeout(() => next(), 10)
})

export default router
